/**
 * 季评 - 面谈准备
 */

import React from 'react';

import { Form } from 'antd';
import { Collapse } from '@/molecules';
import { useCollapse } from '@/hooks';
import { QuestionListFormItem } from '@/containers';
import { usePrepareQuestionsForm, useAssessSetting, usePrepareAlert } from '../hooks';
import { AssessAbilityResult, BottomAction, PrepareAlert, AssessResultDynamic, AssessKPI } from '../containers';
import { TRIAL_ACTION } from '../constants';

const { Panel } = Collapse;

function InterviewPrepareQ({ form, data }) {
    const { getSubmitValues } = usePrepareQuestionsForm(form, data?.interviewPrepareVO);
    const { activeKey, onChange, openAll } = useCollapse(['1', '2', '3', '4'], []);
    const { q = {} } = useAssessSetting(data);
    const { message, renderButton } = usePrepareAlert('Q', data);
    const assessDetail = React.useMemo(
        () => data?.assessQuarterly?.filter(item => item.status !== TRIAL_ACTION.ASSESS_HR_QUARTER),
        []
    );
    return (
        <div>
            <PrepareAlert message={message} renderButton={renderButton} />

            <Collapse bordered={false} activeKey={activeKey} onChange={onChange}>
                <AssessResultDynamic data={data} />
                {q.showKPI && Boolean(data?.performanceTarget?.result) && (
                    <Panel header="季度绩效目标" key="2">
                        <AssessKPI data={data} />
                    </Panel>
                )}
                {q.showAssess && (
                    <Panel header="能力评估" key="3">
                        <AssessAbilityResult data={assessDetail} levels={data?.assessAbility?.levels} />
                    </Panel>
                )}
                <Panel header="面谈自定义问题" key="4">
                    {form.getFieldDecorator('questions')(<QuestionListFormItem style={{ width: 900 }} form={form} />)}
                </Panel>
            </Collapse>

            <BottomAction openAll={openAll} data={data} form={form} params={getSubmitValues} />
        </div>
    );
}

export default Form.create({})(InterviewPrepareQ);
